#include <algorithm>
#include <iostream>
using namespace std;

const int kMaxN = 51;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  for (cin >> T; T; T--) {
    int n, k;
    int a[kMaxN] = {0};

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    for (int i = 0; i < n; i++) {
      if (k >= a[i]) {
        k -= a[i];
      } else {
        break;
      }
    }
    cout << k << "\n";
  }
  return 0;
}